﻿using Bentley.CifNET.LinearGeometry;
using System;
using System.Collections.Generic;
using Bentley.CifNET.GeometryModel.SDK;
using System;
using BCL = Bentley.CifNET.GeometryModel.SDK;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BIM = Bentley.Interop.MicroStationDGN;
using BMI = Bentley.MstnPlatformNET.InteropServices;
using Bentley.CifNET.SDK;
using System.Runtime.ConstrainedExecution;
using Bentley.DgnPlatformNET;
using Newtonsoft.Json;

namespace CheccCoverplateCulvertAssemble.Common
{
    public class AlignmentProperty
    {
        private string stationPrefix;
        private double staStation;
        private double endStation;
        private string highwayLevel;
        private string designSpeed;
        private string widthOfSubgrade;
        private string antiKnock;
        private string autoLoad;
        private string environmentType;
        private BCL.Stationing station;
        private LinearElement linear;
        private Alignment alignment;




        public AlignmentProperty()
        {
        }

        public AlignmentProperty(string stationPrefix, double staStation, double endStation, string highwayLevel, string designSpeed, string widthOfSubgrade, string antiKnock, string autoLoad, string environmentType, Alignment thisAlignment)
        {
            StationPrefix = stationPrefix;
            StaStation = staStation;
            EndStation = endStation;
            HighwayLevel = highwayLevel;
            DesignSpeed = designSpeed;
            WidthOfSubgrade = widthOfSubgrade;
            AntiKnock = antiKnock;
            AutoLoad = autoLoad;
            EnvironmentType = environmentType;
            ThisAlignment = thisAlignment;
        }

        /// <summary>
        /// 当前路线
        /// </summary>
        [JsonIgnore]
        public Alignment ThisAlignment
        {
            get { return alignment; }
            set { alignment = value; }
        }

        /// <summary>
        /// 平面线
        /// </summary>
        [JsonIgnore]
        public LinearElement Linear
        {
            get
            {
                return linear;
            }
            set
            {
                linear = value;
            }
        }

        /// <summary>
        /// 获取路线上的桩号系统
        /// </summary>
        [JsonIgnore]
        public BCL.Stationing Station
        {
            get
            {
                return station;
            }
            set
            {
                station = value;
            }
        }
        /// <summary>
        /// 桩号前缀
        /// </summary>
        public string StationPrefix
        {
            get
            {
                return stationPrefix;
            }
            set
            {
                stationPrefix = value;
            }
        }
        /// <summary>
        /// 起始桩号
        /// </summary>
        public double StaStation
        {
            get
            {
                return staStation;
            }
            set
            {
                staStation = value;
            }
        }
        /// <summary>
        /// 终点桩号
        /// </summary>
        public double EndStation
        {
            get
            {
                return endStation;
            }
            set
            {
                endStation = value;
            }
        }
        /// <summary>
        /// 公路等级
        /// </summary>
        public string HighwayLevel
        {
            get
            {
                return highwayLevel;
            }
            set
            {
                highwayLevel = value;
            }
        }
        /// <summary>
        /// 设计时速
        /// </summary>
        public string DesignSpeed
        {
            get
            {
                return designSpeed;
            }
            set
            {
                designSpeed = value;
            }
        }
        /// <summary>
        /// 路基宽度
        /// </summary>
        public string WidthOfSubgrade
        {
            get
            {
                return widthOfSubgrade;
            }
            set
            {
                widthOfSubgrade = value;
            }
        }
        /// <summary>
        /// 抗震烈度
        /// </summary>
        public string AntiKnock
        {
            get
            {
                return antiKnock;
            }
            set
            {
                antiKnock = value;
            }
        }
        /// <summary>
        /// 汽车荷载
        /// </summary>
        public string AutoLoad
        {
            get
            {
                return autoLoad;
            }
            set
            {
                autoLoad = value;
            }
        }
        /// <summary>
        /// 环境类别
        /// </summary>
        public string EnvironmentType
        {
            get
            {
                return environmentType;
            }
            set
            {
                environmentType = value;
            }
        }

        /// <summary>
        /// 查找目标路线
        /// </summary>
        /// <param name="alignment">检索条件来自于另一个路线</param>
        /// <returns></returns>
        public static Alignment seachTagetAlignment(Alignment alignment)
        {
        //    if (Session.Instance.GetActiveDgnModel().ModelName != "Default")
        //    {
        //        //获取当前模型下所有元素
        //        BIM.Application msApp = BMI.Utilities.ComApp; //得到application
        //        BIM.ModelReference activeModel = msApp.ActiveDesignFile.Models["Default"];
        //        activeModel.Activate();
        //        msApp.RedrawAllViews();
        //    }

            ModelId modelId = Session.Instance.GetActiveDgnFile().FindModelIdByName("Default");
            //根据起终点桩号、公路等级、长度 找到相对应的路线
            ConsensusConnection sdkCon = new ConsensusConnection(Session.Instance.GetActiveDgnFile().FindLoadedModelById(modelId));
            //ConsensusConnection sdkCon = new ConsensusConnection(Session.Instance.GetActiveDgnModel());
            GeometricModel gm = sdkCon.GetActiveGeometricModel();
            foreach (Alignment Ale in gm.Alignments)
            {
                if (Ale == null) continue;
                if (Ale.Element.ElementId == alignment.Element.ElementId)
                {
                    return Ale;
                }
            }
            return null;
        }
    }
}
